<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>物料信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<jsp:include page="${pageContext.request.contextPath }/resource_path.jsp" flush="true"/>
	<link rel="stylesheet" media="all" href="${pageContext.request.contextPath }/assets/formSelects/formSelects-v4.css">
	<link rel="stylesheet" media="all" href="${pageContext.request.contextPath }/assets/formSelects/formSelects-v4.js">
</head>
<body class="layui-anim layui-anim-up">
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
            <cite>物料信息</cite>
        </a>
    </span>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" onsubmit="return false">
            <input type="text" name="keyword" id="keyword" placeholder="请输入物料名称" autocomplete="off" class="layui-input">
            <button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon layui-icon-search"></i>检索</button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn layui-btn-warm" id="add"><i class="layui-icon layui-icon-add-circle-fine"></i>新增</button>
        <button class="layui-btn layui-btn-danger" id="del"><i class="layui-icon layui-icon-delete"></i>批量删除</button>
    </xblock>
    <table class="layui-hide" id="staffList" lay-filter="staffList"></table>
    <script type="text/html" id="rowToolbar">
        <a class="layui-btn layui-btn-xs" lay-event="update"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        <a class="layui-btn layui-btn-xs" lay-event="bindingCustomer"><i class="layui-icon layui-icon-edit"></i>绑定客户</a>
        <a class="layui-btn layui-btn-xs" lay-event="bindingWarehouse"><i class="layui-icon layui-icon-edit"></i>绑定仓库</a>
    </script>
    <div id="formDiv" hidden>
		<div class="box">
		    <form class="layui-form layui-card-body" id="addform">
				<input hidden id="id" name="id">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">客户</label>
						<div class="layui-input-inline" style="width: 285px">
							<select style="width: 285px" class="" name="client" id="client" lay-filter="client" xm-select="select1">
								<c:forEach items="${customerList }" var="c">
									<option value="${c.id }">${c.customer_name }</option>
								</c:forEach>
							</select>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn  layui-btn-blue" lay-submit lay-filter="addform" id="subform">确定</button>
						<button class="layui-btn layui-btn-primary" style="margin-left:120px">取消</button>
					</div>
				</div>
			</form>
		</div>
	</div>
    <div id="formDiv2" hidden>
		<div class="box">
		    <form class="layui-form layui-card-body" id="addform2">
				<input hidden id="id2" name="id">
				<!-- _______________________________________________ -->
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">客户</label>
						<div class="layui-input-inline" style="width: 285px">
							<select style="width: 285px" class="" name="remark" id="client2" lay-filter="client2" xm-select="select1">
								<c:forEach items="${customerList }" var="c">
									<option value="${c.id }">${c.customer_name }</option>
								</c:forEach>
							</select>
						</div>
					</div>
				</div>
				<!-- _______________________________________________ -->
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">仓库</label>
						<div class="layui-input-inline" style="width: 285px">
							<select style="width: 285px" class="" name="ware" id="ware" lay-filter="ware" xm-select="select2">
							
							</select>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn  layui-btn-blue" lay-submit lay-filter="addform2" id="subform2">确定</button>
						<button class="layui-btn layui-btn-primary" style="margin-left:120px">取消</button>
					</div>
				</div>
			</form>
		</div>
	</div>
<script type="text/javascript">
	var opts  = document.getElementById("client");
	function check(id){
		for(var i = 0;i<opts.options.length;i++){
			if(opts.options[i].value == id){
				opts.options[i].setAttribute("selected", "selected");
			}
		}
	}
	//全局定义一次, 加载formSelects
	layui.config({
	    base: '${pageContext.request.contextPath }/assets/formSelects/' //此处路径请自行处理, 可以使用绝对路径
	}).extend({
	    formSelects: 'formSelects-v4'
	});
    layui.use(['table','layer','upload','form','laydate','formSelects'], function(){
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var formSelects = layui.formSelects;
        var $ = layui.jquery, active = {
            reload:function () {
                var keyword01 = $("#keyword").val();
                table.reload('contenttable',{
                    method:'get',
                    where:{"keyword01":keyword01}
                });
            }
        }

        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        table.render({
            elem: '#staffList'
            ,url:'${pageContext.request.contextPath }/materiel/queryMaterielCriteria.do'
            ,title: '物料列表'
            ,id :'contenttable'
            ,limits:[10,20,30]
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'', title:'序号', sort: true, type:'numbers', width: 60}
                ,{field:'container_name', title:'容器名称', width: 90}
                ,{field:'clientName', title:'所属客户', width: 200}
                ,{field:'wareName', title:'存放仓库', width: 200}
                ,{field:'materiel_name', title:'物料名称', width: 90}
                ,{field:'materiel_num', title:'产品码', width: 80}
                ,{field:'brevity_num', title:'简码', width: 80}
                ,{field:'materiel_size', title:'物料规格', width: 90}
                ,{field:'materiel_properties', title:'物料属性', width: 90}
                ,{field:'quality_guarantee_period', title:'保质期', width: 80}
                ,{field:'allowable_storage_days', title:'允许存放天数', width: 120}
                ,{field:'unit', title:'单位', width: 60}
                ,{field:'volume', title:'体积', width: 60}
                ,{field:'weight', title:'重量', width: 60}
                ,{field:'out_date', title:'出厂日期', width: 90, templet: function (row){
                    if(row.out_date != null) {
                        return row.out_date;
                    } else {
                        return "";
                    }
                }}
                ,{field:'code_rule', title:'编码规则', width: 90}
                ,{field:'delivery_address', title:'收货地址', width: 90}
                ,{field:'outgoing_frequency', title:'出库频率', width: 90}
                ,{field:'packing_quantity', title:'包装数量', width: 90}
                ,{field:'is_devanning', title:'是否拆箱', width: 90, templet: function (row){
                    if(row.is_devanning == '0') {
                        return "是";
                    } else {
                        return "否";
                    }
                }}
                ,{field:'devanning_num', title:'拆箱数', width: 80}
                ,{field:'storage_type', title:'入库类型', width: 90, templet: function (row){
                    if(row.storage_type == '0'){
                        return "普通入库";
                    } else {
                        return "精准入库";
                    }
                }}
                ,{field:'barcode_type', title:'条码类型', width: 90, templet: function (row){
                    if(row.barcode_type == '0'){
                        return "系统码";
                    } else if (row.barcode_type == '1') {
                        return "客户码1";
                    } else if (row.barcode_type == '2') {
                        return "客户码2";
                    } else {
                        return "无码";
                    }
                }}
                ,{field:'sequence_number', title:'顺序号', width: 80}
                ,{field:'placement_type', title:'放置类型', width: 90, templet: function (row){
                    if(row.placement_type == '0'){
                        return "货架";
                    } else {
                        return "平地";
                    }
                }}
                ,{field:'removal_container_name', title:'拆箱后容器', width: 100}
                ,{field:'remark', title:'备注', width: 60}
                ,{fixed:'right',unresize: true, title:'操作', toolbar: '#rowToolbar',width:300, align: 'center'}
            ]]
            ,page: true
            ,done : function(){
                $('th').css({
                    'background-color': '#009688', 'color': '#fff','font-weight':'bold',
                })
            }
        });

        //监听复选框事件
        table.on('checkbox(staffList)',function(obj){
            if(obj.checked == true && obj.type == 'all'){
                //点击全选
                $('.layui-table-body table.layui-table tbody tr').addClass('layui-table-click');
            }else if(obj.checked == false && obj.type == 'all'){
                //点击全不选
                $('.layui-table-body table.layui-table tbody tr').removeClass('layui-table-click');
            }else if(obj.checked == true && obj.type == 'one'){
                //点击单行
                if(obj.checked == true){
                    obj.tr.addClass('layui-table-click');
                }else{
                    obj.tr.removeClass('layui-table-click');
                }
            }else if(obj.checked == false && obj.type == 'one'){
                //点击全选之后点击单行
                if(obj.tr.hasClass('layui-table-click')){
                    obj.tr.removeClass('layui-table-click');
                }
            }
        })

        /**
         * 表单校验
         */
        form.verify({
            //value：表单的值、item：表单的DOM对象
            container_id: function(value, item){
                if(value == ''){
                    return '容器名称不能为空';
                }
            },
            client: function(value, item){
                if(value == ''){
                    return '所属客户不能为空';
                }
            },
            materiel_name: function(value, item){
                if(value == ''){
                    return '物料名称不能为空';
                }
            },
            materiel_num: function(value, item){
                if(value == ''){
                    return '物料编号不能为空';
                }
            },
            materiel_size: function(value, item){
                if(value == ''){
                    return '物料规格不能为空';
                }
            },
            materiel_properties: function(value, item){
                if(value == ''){
                    return '物料属性不能为空';
                }
            },
            quality_guarantee_period: function(value, item){
                if(value == ''){
                    return '保质期不能为空';
                }
            },
            allowable_storage_days: function(value, item){
                if(value == ''){
                    return '允许存放天数不能为空';
                }
            },
            out_date: function(value, item){
                if(value == ''){
                    return '出厂日期不能为空';
                }
            }
        });

        //新增
        $("#add").click(function(){
            layer.open({
                type: 1 					//Page层类型
                ,area: ['670px', ''] 	//宽  高
                ,title: '新增'
                ,shade: 0.6 				//遮罩透明度
                ,maxmin: true 				//允许全屏最小化
                ,anim: 1 					//0-6的动画形式，-1不开启
                ,content:
                    '<div id="addDivID">'+
                        '<form class="layui-form" id="addFormID">'+
                            '<xblock>'+
                                '<table>'+
                                    '<tr style="height: 10px"></tr>'+
                                    '<tr>'+
	                                    '<td><label class="layui-form-label">容器名称</label></td>'+
	                                    '<td>'+
	                                        '<div style="width: 190px; float: left;">' +
		                                        '<select id="container_id" name="container_id" lay-verify="container_id">' +
		                                            '<option value="">请选择</option>' +
		                                        '</select>'+
		                                    '</div>'+
		                                    '<div style="margin-top: 12px;">'+
		                                        '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
		                                    '</div>'+
	                                    '</td>'+
	                                    '<td><label class="layui-form-label">放置类型</label></td>'+
	                                    '<td>'+
	                                        '<div style="width: 190px; float: left;">' +
	                                            '<select id="placement_type" name="placement_type" lay-verify="placement_type">' +
	                                                '<option value="0">货架</option>' +
	                                                '<option value="1">平地</option>' +
	                                            '</select>'+
	                                        '</div>'+
	                                        '<div style="margin-top: 12px;">'+
	                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
	                                        '</div>'+
	                                    '</td>'+
                                    '</tr>'+
                                    '<tr style="height: 10px"></tr>'+
                                    '<tr>'+
                                        '<td><label class="layui-form-label">物料名称</label></td>'+
                                        '<td>'+
                                            '<input class="layui-input" id="materiel_name" name="materiel_name" lay-verify="materiel_name" style="width: 190px; display:inline">'+
                                            '<div class="layui-inline" style="margin-top: 10px;">'+
                                                '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
                                            '</div>'+
                                        '</td>'+
                                        '<td><label class="layui-form-label">产品码</label></td>'+
                                        '<td>'+
                                            '<input class="layui-input" id="materiel_num" name="materiel_num" lay-verify="materiel_num" style="width: 190px; display:inline">'+
                                            '<div class="layui-inline" style="margin-top: 10px;">'+
                                                '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
                                            '</div>'+
                                        '</td>'+
                                    '</tr>'+
                                    '<tr style="height: 10px"></tr>'+
                                    '<tr>'+
	                                    '<td><label class="layui-form-label">简码</label></td>'+
	                                    '<td>'+
	                                        '<input class="layui-input" id="brevity_num" name="brevity_num" lay-verify="brevity_num" style="width: 190px; display:inline">'+
	                                        '<div class="layui-inline" style="margin-top: 10px;">'+
	                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
	                                        '</div>'+
	                                    '</td>'+
                                        '<td><label class="layui-form-label">物料规格</label></td>'+
                                        '<td>'+
                                            '<input class="layui-input" id="materiel_size" name="materiel_size" lay-verify="materiel_size" style="width: 190px; display:inline">'+
                                            '<div class="layui-inline" style="margin-top: 10px;">'+
                                                '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
                                            '</div>'+
                                        '</td>'+
                                    '</tr>'+
                                    '<tr style="height: 10px"></tr>'+
                                    '<tr>'+
                                        '<td><label class="layui-form-label">物料属性</label></td>'+
                                        '<td>'+
                                            '<input class="layui-input" id="materiel_properties" name="materiel_properties" lay-verify="materiel_properties" style="width: 190px; display:inline">'+
                                            '<div class="layui-inline" style="margin-top: 10px;">'+
                                                '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
                                            '</div>'+
                                        '</td>'+
                                        '<td><label class="layui-form-label">保质期</label></td>'+
                                        '<td>'+
                                            '<input class="layui-input" id="quality_guarantee_period" name="quality_guarantee_period" lay-verify="quality_guarantee_period" style="width: 190px; display:inline">'+
                                            '<div class="layui-inline" style="margin-top: 10px;">'+
                                                '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
                                            '</div>'+
                                        '</td>'+
                                    '</tr>'+
                                    '<tr style="height: 10px"></tr>'+
                                    '<tr>'+
                                        '<td><label class="layui-form-label">存放天数</label></td>'+
                                        '<td>'+
                                            '<input class="layui-input" id="allowable_storage_days" name="allowable_storage_days" lay-verify="allowable_storage_days" style="width: 190px; display:inline">'+
                                            '<div class="layui-inline" style="margin-top: 10px;">'+
                                                '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
                                            '</div>'+
                                        '</td>'+
                                        '<td><label class="layui-form-label">单位</label></td>'+
                                        '<td>'+
                                            '<input class="layui-input" id="unit" name="unit" style="width: 190px;">'+
                                        '</td>'+
                                    '</tr>'+
                                    '<tr style="height: 10px"></tr>'+
                                    '<tr>'+
	                                    '<td><label class="layui-form-label">体积</label></td>'+
	                                    '<td>'+
	                                        '<input class="layui-input" id="volume" name="volume" style="width: 190px;">'+
	                                    '</td>'+
	                                    '<td><label class="layui-form-label">重量</label></td>'+
	                                    '<td>'+
	                                        '<input class="layui-input" id="weight" name="weight" style="width: 190px;">'+
	                                    '</td>'+
                                    '</tr>'+
                                    '<tr style="height: 10px"></tr>'+
                                    '<tr>'+
	                                    '<td><label class="layui-form-label">出厂日期</label></td>'+
	                                    '<td>'+
	                                        '<input class="layui-input" id="out_date" name="out_date" lay-verify="out_date" style="width: 190px; display:inline">'+
                                            '<div class="layui-inline" style="margin-top: 10px;">'+
                                                '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
                                            '</div>'+
	                                    '</td>'+
	                                    '<td><label class="layui-form-label">编码规则</label></td>'+
	                                    '<td>'+
	                                        '<input class="layui-input" id="code_rule" name="code_rule" style="width: 190px;">'+
	                                    '</td>'+
                                    '</tr>'+
                                    '<tr style="height: 10px"></tr>'+
                                    '<tr>'+
	                                    '<td><label class="layui-form-label">收货地址</label></td>'+
	                                    '<td>'+
	                                        '<input class="layui-input" id="delivery_address" name="delivery_address" style="width: 190px;">'+
	                                    '</td>'+
	                                    '<td><label class="layui-form-label">出库频率</label></td>'+
	                                    '<td>'+
	                                        '<input class="layui-input" id="outgoing_frequency" name="outgoing_frequency" style="width: 190px;">'+
	                                    '</td>'+
                                    '</tr>'+
                                    '<tr style="height: 10px"></tr>'+
                                    '<tr>'+
	                                    '<td><label class="layui-form-label">包装数量</label></td>'+
	                                    '<td>'+
	                                        '<input class="layui-input" id="packing_quantity" name="packing_quantity" style="width: 190px;">'+
	                                    '</td>'+
	                                    '<td><label class="layui-form-label">是否拆箱</label></td>'+
	                                    '<td>'+
	                                        '<div style="width: 190px; float: left;">' +
	                                            '<select name="is_devanning" lay-verify="is_devanning">' +
	                                                '<option value="0">是</option>' +
	                                                '<option value="1">否</option>' +
	                                            '</select>'+
	                                        '</div>'+
	                                        '<div style="margin-top: 12px;">'+
	                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
	                                        '</div>'+
	                                    '</td>'+
                                    '</tr>'+
                                    '<tr style="height: 10px"></tr>'+
                                    '<tr>'+
	                                    '<td><label class="layui-form-label">拆箱数</label></td>'+
	                                    '<td>'+
	                                        '<input class="layui-input" id="devanning_num" name="devanning_num" style="width: 190px;">'+
	                                    '</td>'+
	                                    '<td><label class="layui-form-label">入库类型</label></td>'+
	                                    '<td>'+
	                                        '<div style="width: 190px; float: left;">' +
	                                            '<select id="storage_type" name="storage_type" lay-verify="storage_type">' +
                                                    '<option value="0">普通入库</option>' +
	                                                '<option value="1">精准入库</option>' +
	                                            '</select>'+
	                                        '</div>'+
	                                        '<div style="margin-top: 12px;">'+
	                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
	                                        '</div>'+
	                                    '</td>'+
                                    '</tr>'+
                                    '<tr style="height: 10px"></tr>'+
                                    '<tr>'+
	                                    '<td><label class="layui-form-label">条码类型</label></td>'+
	                                    '<td>'+
	                                        '<div style="width: 190px; float: left;">' +
	                                            '<select id="barcode_type" name="barcode_type" lay-verify="barcode_type">' +
	                                                '<option value="0">系统码</option>' +
	                                                '<option value="1">客户码1</option>' +
	                                                '<option value="2">客户码2</option>' +
	                                                '<option value="3">无码</option>' +
	                                            '</select>'+
	                                        '</div>'+
	                                        '<div style="margin-top: 12px;">'+
	                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
	                                        '</div>'+
	                                    '</td>'+
	                                    '<td><label class="layui-form-label">顺序号</label></td>'+
	                                    '<td>'+
	                                        '<input class="layui-input" id="sequence_number" name="sequence_number" style="width: 190px;">'+
	                                    '</td>'+
                                    '</tr>'+
                                    '<tr style="height: 10px"></tr>'+
                                    '<tr>'+
	                                    '<td><label class="layui-form-label">拆箱后容器</label></td>'+
	                                    '<td>'+
		                                    '<div style="width: 190px; float: left;">' +
		                                        '<select id="removal_container" name="removal_container" lay-verify="removal_container">' +
		                                            '<option value="">请选择</option>' +
		                                        '</select>'+
	                                    	'</div>'+
	                                    '</td>'+
	                                    '<td><label class="layui-form-label">拆箱产品码</label></td>'+
	                                    '<td>'+
	                                        '<input class="layui-input" id="devanning_code" name="devanning_code" style="width: 190px;">'+
	                                    '</td>'+
                                    '</tr>'+
	                                '<tr style="height: 10px"></tr>'+
                                    '<tr>'+
	                                   '<td><label class="layui-form-label">备注</label></td>'+
	                                   '<td colspan="3">'+
	                                       '<input class="layui-input" id="remark" name="remark" value="" style="width: 504px">'+
	                                   '</td>'+
	                               '</tr>'+
                                    '<tr style="height: 10px"></tr>'+
                                    '<tr style="height: 20px">'+
                                    '<tr align="center">'+
                                        '<td colspan="2"><button class="layui-btn layui-btn-blue" id="subBtn" lay-submit lay-filter="addForm" style="margin-left:160px; margin-bottom: 10px">提交</button></td>'+
                                        '<td colspan="2">&emsp;&emsp;&emsp;&emsp;<button class="layui-btn layui-btn-primary" style="margin-bottom: 10px">取消</button></td>'+
                                    '</tr>'+
                                '</table>'+
                            '</xblock>'+
                        '</form>'+
                    '</div>'
                ,success: function(){
                    //下拉框查找所有容器
                    $.ajax({
                        type: 'POST',
                        url: '${pageContext.request.contextPath}/materiel/queryAllContainer.do',
                        dataType: 'json',
                        async: false,
                        success: function (datas){
                            for (var i = 0; i < datas.length; i++) {
                                $("#container_id").append("<option value='"+ datas[i].id +"'>"+ datas[i].container_name +"</option>");
                                $("#removal_container").append("<option value='"+ datas[i].id +"'>"+ datas[i].container_name +"</option>");
                            }
                        }
                    });
                    //下拉框查找所有客户
                    $.ajax({
                        type: 'POST',
                        url: '${pageContext.request.contextPath}/stockOutOrder/queryAllCustomer.do',
                        dataType: 'json',
                        async: false,
                        success: function (datas){
                            for (var i = 0; i < datas.length; i++) {
                                $("#client").append("<option value='"+ datas[i].customer_name +"'>"+ datas[i].customer_name +"</option>");
                            }
                        }
                    });

                    laydate.render({
                        elem: '#out_date'
                    });
                    form.render();
                }
            });
        });

        //编辑
        table.on('tool(staffList)', function(obj){
            var data = obj.data;
            var mid = data.id;
    		if(obj.event === 'update'){
	            layer.open({
	                type: 1 				//Page层类型
	                ,area: ['670px', ''] 	//宽  高
	                ,title: '编辑'
	                ,shade: 0.6 			//遮罩透明度
	                ,maxmin: true 			//允许全屏最小化
	                ,anim: 1 				//0-6的动画形式，-1不开启
	                ,content:
	                    '<div id="updateDivID">'+
	                        '<form class="layui-form" id="updateFormID">'+
	                            '<xblock>'+
	                                '<table>'+
	                                    '<tr style="height: 10px"></tr>'+
	                                    '<tr>'+
	                                        '<td>'+
	                                            '<input class="layui-hide" id="id" name="id" value="'+data.id+'">'+
	                                        '</td>'+
	                                    '</tr>'+
	                                    '<tr>'+
		                                    '<td><label class="layui-form-label">容器名称</label></td>'+
		                                    '<td>'+
		                                        '<div style="width: 190px; float: left;">' +
			                                        '<select id="container_id" name="container_id" lay-verify="container_id">' +
			                                            '<option value="">请选择</option>' +
			                                        '</select>'+
			                                    '</div>'+
			                                    '<div style="margin-top: 12px;">'+
			                                        '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
			                                    '</div>'+
		                                    '</td>'+
		                                    '<td><label class="layui-form-label">放置类型</label></td>'+
		                                    '<td>'+
		                                        '<div style="width: 190px; float: left;">' +
		                                            '<select id="placement_type" name="placement_type" lay-verify="placement_type">' +
		                                                '<option value="0">货架</option>' +
		                                                '<option value="1">平地</option>' +
		                                            '</select>'+
		                                        '</div>'+
		                                        '<div style="margin-top: 12px;">'+
		                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
		                                        '</div>'+
		                                    '</td>'+
		                                '</tr>'+
		                                '<tr style="height: 10px"></tr>'+
		                                '<tr>'+
		                                    '<td><label class="layui-form-label">物料名称</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="materiel_name" name="materiel_name" value="'+data.materiel_name+'" lay-verify="materiel_name" style="width: 190px; display:inline">'+
		                                        '<div class="layui-inline" style="margin-top: 10px;">'+
		                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
		                                        '</div>'+
		                                    '</td>'+
		                                    '<td><label class="layui-form-label">产品码</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="materiel_num" name="materiel_num" value="'+data.materiel_num+'" lay-verify="materiel_num" style="width: 190px; display:inline">'+
		                                        '<div class="layui-inline" style="margin-top: 10px;">'+
		                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
		                                        '</div>'+
		                                    '</td>'+
		                                '</tr>'+
		                                '<tr style="height: 10px"></tr>'+
		                                '<tr>'+
		                                    '<td><label class="layui-form-label">简码</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="brevity_num" name="brevity_num" value="'+data.brevity_num+'" lay-verify="brevity_num" style="width: 190px; display:inline">'+
		                                        '<div class="layui-inline" style="margin-top: 10px;">'+
		                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
		                                        '</div>'+
		                                    '</td>'+
		                                    '<td><label class="layui-form-label">物料规格</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="materiel_size" name="materiel_size" value="'+data.materiel_size+'" lay-verify="materiel_size" style="width: 190px; display:inline">'+
		                                        '<div class="layui-inline" style="margin-top: 10px;">'+
		                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
		                                        '</div>'+
		                                    '</td>'+
		                                '</tr>'+
		                                '<tr style="height: 10px"></tr>'+
		                                '<tr>'+
		                                    '<td><label class="layui-form-label">物料属性</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="materiel_properties" name="materiel_properties" value="'+data.materiel_properties+'" lay-verify="materiel_properties" style="width: 190px; display:inline">'+
		                                        '<div class="layui-inline" style="margin-top: 10px;">'+
		                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
		                                        '</div>'+
		                                    '</td>'+
		                                    '<td><label class="layui-form-label">保质期</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="quality_guarantee_period" name="quality_guarantee_period" value="'+data.quality_guarantee_period+'" lay-verify="quality_guarantee_period" style="width: 190px; display:inline">'+
		                                        '<div class="layui-inline" style="margin-top: 10px;">'+
		                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
		                                        '</div>'+
		                                    '</td>'+
		                                '</tr>'+
		                                '<tr style="height: 10px"></tr>'+
		                                '<tr>'+
		                                    '<td><label class="layui-form-label">存放天数</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="allowable_storage_days" name="allowable_storage_days" value="'+data.allowable_storage_days+'" lay-verify="allowable_storage_days" style="width: 190px; display:inline">'+
		                                        '<div class="layui-inline" style="margin-top: 10px;">'+
		                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
		                                        '</div>'+
		                                    '</td>'+
		                                    '<td><label class="layui-form-label">单位</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="unit" name="unit" value="'+data.unit+'" style="width: 190px;">'+
		                                    '</td>'+
		                                '</tr>'+
		                                '<tr style="height: 10px"></tr>'+
		                                '<tr>'+
		                                    '<td><label class="layui-form-label">体积</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="volume" name="volume" value="'+data.volume+'" style="width: 190px;">'+
		                                    '</td>'+
		                                    '<td><label class="layui-form-label">重量</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="weight" name="weight" value="'+data.weight+'" style="width: 190px;">'+
		                                    '</td>'+
		                                '</tr>'+
		                                '<tr style="height: 10px"></tr>'+
		                                '<tr>'+
		                                    '<td><label class="layui-form-label">出厂日期</label></td>'+
		                                    '<td>'+
	                                            '<input class="layui-input" id="out_date" name="out_date" value="'+data.out_date+'" lay-verify="out_date" style="width: 190px; display:inline">'+
	                                            '<div class="layui-inline" style="margin-top: 10px;">'+
	                                                '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
	                                            '</div>'+
		                                    '</td>'+
		                                    '<td><label class="layui-form-label">编码规则</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="code_rule" name="code_rule" value="'+data.code_rule+'" style="width: 190px;">'+
		                                    '</td>'+
		                                '</tr>'+
		                                '<tr style="height: 10px"></tr>'+
		                                '<tr>'+
		                                    '<td><label class="layui-form-label">收货地址</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="delivery_address" name="delivery_address" value="'+data.delivery_address+'" style="width: 190px;">'+
		                                    '</td>'+
		                                    '<td><label class="layui-form-label">出库频率</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="outgoing_frequency" name="outgoing_frequency" value="'+data.outgoing_frequency+'" style="width: 190px;">'+
		                                    '</td>'+
		                                '</tr>'+
		                                '<tr style="height: 10px"></tr>'+
		                                '<tr>'+
		                                    '<td><label class="layui-form-label">包装数量</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="packing_quantity" name="packing_quantity" value="'+data.packing_quantity+'" style="width: 190px;">'+
		                                    '</td>'+
		                                    '<td><label class="layui-form-label">是否拆箱</label></td>'+
		                                    '<td>'+
		                                        '<div style="width: 190px; float: left;">' +
		                                            '<select name="is_devanning" lay-verify="is_devanning">' +
		                                                '<option value="0">是</option>' +
		                                                '<option value="1">否</option>' +
		                                            '</select>'+
		                                        '</div>'+
		                                        '<div style="margin-top: 12px;">'+
		                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
		                                        '</div>'+
		                                    '</td>'+
		                                '</tr>'+
		                                '<tr style="height: 10px"></tr>'+
		                                '<tr>'+
		                                    '<td><label class="layui-form-label">拆箱数</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="devanning_num" name="devanning_num" value="'+data.devanning_num+'" style="width: 190px;">'+
		                                    '</td>'+
		                                    '<td><label class="layui-form-label">入库类型</label></td>'+
		                                    '<td>'+
		                                        '<div style="width: 190px; float: left;">' +
		                                            '<select id="storage_type" name="storage_type" lay-verify="storage_type">' +
	                                                    '<option value="0">普通入库</option>' +
	                                                    '<option value="1">精准入库</option>' +
		                                            '</select>'+
		                                        '</div>'+
		                                        '<div style="margin-top: 12px;">'+
		                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
		                                        '</div>'+
		                                    '</td>'+
		                                '</tr>'+
		                                '<tr style="height: 10px"></tr>'+
		                                '<tr>'+
		                                    '<td><label class="layui-form-label">条码类型</label></td>'+
		                                    '<td>'+
		                                        '<div style="width: 190px; float: left;">' +
		                                            '<select id="barcode_type" name="barcode_type" lay-verify="barcode_type">' +
		                                                '<option value="0">系统码</option>' +
		                                                '<option value="1">客户码1</option>' +
		                                                '<option value="2">客户码2</option>' +
		                                                '<option value="3">无码</option>' +
		                                            '</select>'+
		                                        '</div>'+
		                                        '<div style="margin-top: 12px;">'+
		                                            '<span style="color:red; font-size: 24px; margin-left: 4px">*</span>'+
		                                        '</div>'+
		                                    '</td>'+
		                                    '<td><label class="layui-form-label">顺序号</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="sequence_number" name="sequence_number" value="'+data.sequence_number+'" style="width: 190px;">'+
		                                    '</td>'+
		                                '</tr>'+
		                                '<tr style="height: 10px"></tr>'+
		                                '<tr>'+
		                                    
		                                    '<td><label class="layui-form-label">拆箱后容器</label></td>'+
		                                    '<td>'+
			                                    '<div style="width: 190px; float: left;">' +
			                                        '<select id="removal_container" name="removal_container" lay-verify="removal_container">' +
			                                            '<option value="">请选择</option>' +
			                                        '</select>'+
			                                	'</div>'+
		                                    '</td>'+
		                                    '<td><label class="layui-form-label">拆箱产品码</label></td>'+
		                                    '<td>'+
		                                        '<input class="layui-input" id="devanning_code" name="devanning_code" style="width: 190px;" value = "'+data.devanning_code+'">'+
		                                    '</td>'+
		                                '</tr>'+
		                                '<tr style="height: 10px"></tr>'+
		                                '<tr>'+
		                                    '<td><label class="layui-form-label">备注</label></td>'+
		                                    '<td colspan="3">'+
		                                        '<input class="layui-input" id="remark" name="remark" value="'+data.remark+'" style="width: 504px">'+
		                                    '</td>'+
		                                '</tr>'+
		                                '<tr style="height: 20px">'+
		                                '<tr align="center">'+
		                                    '<td colspan="2"><button class="layui-btn layui-btn-blue" lay-submit lay-filter="updateForm" style="margin-left:160px; margin-bottom: 10px">提交</button></td>'+
		                                    '<td colspan="2">&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 10px">重置</button></td>'+
		                                '</tr>'+
	                                '</table>'+
	                            '</xblock>'+
	                        '</form>'+
	                    '</div>'
	                ,success: function(){
	                    //下拉框查找所有容器
	                    $.ajax({
	                        type: 'POST',
	                        url: '${pageContext.request.contextPath}/materiel/queryAllContainer.do',
	                        dataType: 'json',
	                        async: false,
	                        success: function (datas){
	                            for (var i = 0; i < datas.length; i++) {
	                                $("#container_id").append("<option value='"+ datas[i].id +"'>"+ datas[i].container_name +"</option>");
	                                if(datas[i].id == data.container_id){
	                                    $("#container_id").val(data.container_id);
	                                }
	                                $("#removal_container").append("<option value='"+ datas[i].id +"'>"+ datas[i].container_name +"</option>");
	                                if(datas[i].id == data.removal_container){
	                                    $("#removal_container").val(data.removal_container);
	                                }
	                            }
	                        }
	                    });
	                    //下拉框查找所有客户
	                    $.ajax({
	                        type: 'POST',
	                        url: '${pageContext.request.contextPath}/stockOutOrder/queryAllCustomer.do',
	                        dataType: 'json',
	                        async: false,
	                        success: function (datas){
	                            for (var i = 0; i < datas.length; i++) {
	                                $("#client").append("<option value='"+ datas[i].customer_name +"'>"+ datas[i].customer_name +"</option>");
	                                if(datas[i].customer_name == data.client){
	                                    $("#client").val(data.client);
	                                }
	                            }
	                        }
	                    });
	                    laydate.render({
	                        elem: '#out_date'
	                    });
	                    $("#barcode_type").val(data.barcode_type);
	                    $("#placement_type").val(data.placement_type);
	                    $("#storage_type").val(data.storage_type);
	                    form.render();
	                }
	            });
    		}else if(obj.event === 'bindingCustomer'){
    			layer.open({
	                type: 1 				//Page层类型
	                ,area: ['500px', ''] 	//宽  高
	                ,title: '绑定客户'
	                ,shade: 0.6 			//遮罩透明度
	                ,maxmin: true 			//允许全屏最小化
	                ,anim: 1 				//0-6的动画形式，-1不开启
	                ,content:$('#formDiv')
	                ,success:function(){
	                	$("#id").val(data.id);
	                	var client = data.client;
	                	var c = client.split(",");
	                	for(var i = 0;i<c.length;i++){
	                		if(c[i]!=""){
	                			check(c[i])
	                		}
	                	}
	                	form.render();
	                }
		   			,end: function () {
		   				
			  	  	}
    			});
    		} else if (obj.event === 'bindingWarehouse'){
    			layer.open({
	                type: 1 				//Page层类型
	                ,area: ['500px', ''] 	//宽  高
	                ,title: '绑定仓库'
	                ,shade: 0.6 			//遮罩透明度
	                ,maxmin: true 			//允许全屏最小化
	                ,anim: 1 				//0-6的动画形式，-1不开启
	                ,content:$('#formDiv2')
	                ,success:function(){
	                	$("#id2").val(data.id);
	                	$.ajax({
	                    	type:'post'
	                    	,url:'${pageContext.request.contextPath }/materiel/wareTree.do?regionType='+data.placement_type
	                    	,dataType:'json'
	                    	,success:function(data){
	            		        formSelects.data('select2', 'local', {
	            		            arr: data.rows,
	            		            linkage: true
	            		        });
	                    	}
	                    })
	                    
	                    $.ajax({
	                        type: 'POST',
	                        url: '${pageContext.request.contextPath}/stockOutOrder/queryAllCustomer.do',
	                        dataType: 'json',
	                        async: false,
	                        success: function (datas){
	                            for (var i = 0; i < datas.length; i++) {
	                                $("#client2").append("<option value='"+ datas[i].customer_name +"'>"+ datas[i].customer_name +"</option>");
	                                if(datas[i].customer_name == data.client){
	                                    $("#client2").val(data.client);
	                                }
	                            }
	                        }
	                    });
	                }
    			});
    		}
    		
        });

        //批量删除
        $("#del").click(function(){
            var rowData = table.checkStatus('contenttable');
            var data = rowData.data;
            var idArr = new Array();
            if(data.length == 0){
                toastrStyle();
                toastr.warning("请至少选择一条记录！");
            } else {
                for(var i=0;i < data.length;i++){
                    idArr[i] = data[i].id;
                }
                $.ajax({
                    type:'post',
                    url:'${pageContext.request.contextPath }/materiel/deleteMaterielById.do',
                    data:{"idArr" : idArr},
                    success:function(data){
                        layer.confirm('确定删除吗？', function(){
                            if(data > 0){
                                toastr.success("删除成功！");
                                setTimeout(function(){
                                    location.reload();
                                },1000);
                                setTimeout(function(){
                                    window.location.reload();
                                },2000);
                            }else{
                                toastr.warning("删除失败！");
                                location.reload();
                            }
                        });
                    }
                });
            }
        });

        /**
         * 通用表单提交(AJAX方式)
         */
        form.on('submit(addForm)', function () {
            $.ajax({
                type:'post',
                url:'${pageContext.request.contextPath }/materiel/addMateriel.do',
                data:$("#addFormID").serialize(),
                cache:false,
            }).done(
                function(res) {
                    if (res > 0) {
                        toastr.success('新增成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function() {
                    toastr.error('新增失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        })

        /**
         * 通用表单编辑(AJAX方式)
         */
        form.on('submit(updateForm)', function () {
            $.ajax({
                type : 'post',
                url : '${pageContext.request.contextPath }/materiel/updateMateriel.do',
                data : $("#updateFormID").serialize(),
                cache : false,
            }).done(
                function(res) {
                    if (res > 0) {
                        toastr.success('修改成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function() {
                    toastr.error('修改失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        })
        //绑定客户
        form.on('submit(addform)', function (data) {
        	$("#subform").attr("disabled",true);
        	$.ajax({
        		url : '${pageContext.request.contextPath }/materiel/bindingCustomer.do',
       			data : $('#addform').serialize(),
       			type : "post",
       			//dataType : "json",
    			}).done(
    				function(res) {
    		  			if(res>0){
    		  				toastr.success('绑定成功！');
    	                    setTimeout(function(){
    	                        location.reload();
    	                    },2000);
    		  			}
    				}
    			)
    			return false;
        });
        //绑定仓库
        form.on('submit(addform2)', function (data) {
        	$("#subform2").attr("disabled",true);
        	$.ajax({
        		url : '${pageContext.request.contextPath }/materiel/bindingWarehouse.do',
       			data : $('#addform2').serialize(),
       			type : "post",
       			//dataType : "json",
    			}).done(
    				function(res) {
    		  			if(res>0){
    		  				toastr.success('绑定成功！');
    	                    setTimeout(function(){
    	                        location.reload();
    	                    },2000);
    		  			}else{
    		  				toastr.success('清空绑定！');
    	                    setTimeout(function(){
    	                        location.reload();
    	                    },2000);
    		  				
    		  			}
    				}
    			)
    			return false;
        });
    });
    toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
    //日期格式转换
    function dateToStr(date) {
        var time = new Date(date.time);
        var y = time.getFullYear();
        var M = time.getMonth() + 1;
        M = M < 10 ? ("0" + M) : M;
        var d = time.getDate();
        d = d < 10 ? ("0" + d) : d;
        var str = y + "-" + M + "-" + d;
        return str;
    }
</script>
</body>
</html>
